package com.shioirikukuri.mapper;

import com.shioirikukuri.entity.ReservationOrder;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ReservationOrderMapper {

	/**
	 * 查询所有预约订单
	 *
	 * @return 预约订单列表
	 */
	@Select("SELECT * FROM reservation_order")
	List<ReservationOrder> selectAllReservationOrders();

	/**
	 * 根据预约订单ID查询预约订单
	 *
	 * @param orderId 预约订单ID
	 * @return 匹配的预约订单对象
	 */
	@Select("SELECT * FROM reservation_order WHERE order_id = #{orderId}")
	ReservationOrder selectReservationOrderById(@Param("orderId") Integer orderId);

	/**
	 * 根据预约类型查询预约订单
	 *
	 * @param reservationType 预约类型
	 * @return 匹配的预约订单列表
	 */
	@Select("SELECT * FROM reservation_order WHERE reservation_type = #{reservationType}")
	List<ReservationOrder> selectReservationOrdersByType(@Param("reservationType") String reservationType);

	/**
	 * 插入新的预约订单
	 *
	 * @param reservationOrder 新预约订单的信息
	 */
	@Insert("INSERT INTO reservation_order(phone_number, reservation_type, seat_count, service_total_price, reservation_date, time_slot) VALUES( #{phoneNumber}, #{reservationType}, #{seatCount}, #{serviceTotalPrice}, #{reservationDate}, #{timeSlot})")
	@Options(useGeneratedKeys = true, keyProperty = "orderId")
	void insertReservationOrder(ReservationOrder reservationOrder);

	/**
	 * 更新已有预约订单的信息
	 *
	 * @param reservationOrder 需要更新的预约订单信息
	 */
	@Update("UPDATE reservation_order SET phone_number=#{phoneNumber}, reservation_type=#{reservationType}, seat_count=#{seatCount}, service_total_price=#{serviceTotalPrice}, reservation_date=#{reservationDate}, time_slot=#{timeSlot} WHERE order_id=#{orderId}")
	void updateReservationOrder(ReservationOrder reservationOrder);

	/**
	 * 删除指定ID的预约订单
	 *
	 * @param orderId 预约订单ID
	 */
	@Delete("DELETE FROM reservation_order WHERE order_id = #{orderId}")
	void deleteReservationOrderById(@Param("orderId") Integer orderId);

}